package com.sneakxy.mybase4j.generator.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * 字符串其他工具
 * @author 潜行的青衣
 * @see
 */
public class StringExtUtils {

	public static String formatStringName(String str) {
		String name = StringUtils.lowerCase(str);
		StringBuilder s = new StringBuilder();
		if(StringUtils.contains(name, "_")) {
			String[] parts = StringUtils.split(name, "_");
			for(String part:parts) {
				s.append(upperCaseFirstChar(part));
			}
		} else {
			s.append(upperCaseFirstChar(name));
		}
		return s.toString();
	}
	
	public static String upperCaseFirstChar(String name) {
		StringBuilder s = new StringBuilder();
		s.append(StringUtils.substring(name, 0, 1).toUpperCase());
		s.append(StringUtils.substring(name, 1));
		return s.toString();
	}
	
	public static String lowerCaseFirstChar(String name) {
		StringBuilder s = new StringBuilder();
		s.append(StringUtils.substring(name, 0, 1).toLowerCase());
		s.append(StringUtils.substring(name, 1));
		return s.toString();
	}
}
